package com.cloud.workTest;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import java.util.Properties;

public class PropertistTest {
    public static void main(String[] args) throws Exception{
        SAXReader reader = new SAXReader();
//        Document document = reader.read("src/main/resources/configuration.xml");
        InputStream ins = PropertistTest.class.getClassLoader().getResourceAsStream("configuration.xml");
        Document document =reader.read(ins);
        Element configEle = document.getRootElement();

        Element propertiesEle = configEle.element("properties");
        String jdbcPropertiesPath = propertiesEle.attributeValue("resource");
        //不需要在同一个目录下，在resources文件下也可以
        InputStream inputStream = PropertistTest.class.getClassLoader().getResourceAsStream(jdbcPropertiesPath);
        Properties properties = new Properties();
        properties.load(inputStream);
        System.out.println(properties.getProperty("url"));
        System.out.println(properties.getProperty("driver"));
        System.out.println(properties.getProperty("password"));
        System.out.println(properties.getProperty("username"));

    }
}
